package jt.classic.app.ldrc;

import jt.classic.app.ldrc.impl.ALdrcImpl;

import jt.classic.system.SimpleManager;

import java.sql.Connection;

import java.util.List;
import java.util.Map;

/**
 * 领导日程管理者
 * 
 * @author bizkit
 *
 */
public class LdrcManager extends SimpleManager {
    public LdrcManager() {
        super();
    }

    public LdrcManager(Connection conn) {
        super(conn);
    }
    
    /**
     * 根据领导日程ID得到领导日程
     * 
     * @param id 领导日程ID
     * @return ALdrc
     */
    public ALdrc getALdrcById(String id) {
        String sql = "SELECT * FROM APP_LDRC WHERE ID = '" + id+ "'";

        Map info = this.trimmer.searchSingleData(sql);
        ALdrc ldrc = null;

        if (info != null) {
            sql = "SELECT * FROM APP_LDRC_YHLD WHERE ID = '" + id+ "'";

            List list = this.trimmer.searchMultiData(sql);

            String yhld = "";

            for (int i = 0; i < list.size(); i++) {
                Map temp = (Map) list.get(i);
                String uid = (String) temp.get("LD_ID");
                String groupid = (String) temp.get("LD_GROUPID");

                yhld += (uid + "@" + groupid + ",");
            }

            info.put("YHLD", yhld);

            ldrc = new ALdrcImpl();
            ldrc.reload(info);
        }

        return ldrc;
    }
}
